const {
    render
} = require('less')

require('../less/courseList.less')
document.ready(function () {
    window.utils.jumpPage('run')
    window.utils.checkPage('courseList')
    //获取元素节点
    let newCourse = document.getElementById('newCourse')
    let otherLesson = document.getElementById('otherLesson')
    window.$http.get('/sports/allcourse', function (res) {
        if (res.status == 0) {
            render(res.data)
            console.log(res.data);
            // console.log(otherLesson);
            // console.log(newCourse);
        }
    })

    function render(data) {
        let listData = data.filter(function (v) {
            return v.latest == 1
        })
        newCourse.innerHTML = `
    <h2 class="mt10">最新课程</h2>
 <div class="newLesson">
 <a href="courseDetail.html?courseId=${listData[0].courseId}"> <img src="http://139.9.177.51:8099${listData[0].imgurl}" alt=""></a>
 <p>${listData[0].name}</p>
 <p class="c9a f12">${listData[0].desc}</p>
  </div>`
        let list = data.filter(function (v) {
            return v.latest == 0
        })
        // console.log(list);
        let courseList = '';
        for (let i = 0; i < list.length; i++) {
            courseList += `
    <div class="lesson">
    <h2 class="mt10">
        课程
    </h2>
    <div class="newLesson">
        <a href="courseDetail.html?courseId=${list[i].courseId}"> <img src="http://139.9.177.51:8099${list[i].imgurl}" alt=""></a>
        <p>${list[i].name}</p>
        <p class="c9a f12">${list[i].desc}</p>
    </div>
</div>
    `
        }

        otherLesson.innerHTML = courseList
    }









})